package exam.huawei;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/15 22:31
 */
public class HJ43 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] maze = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                maze[i][j] = in.nextInt();
            }
        }
        ArrayList<int[]> list = new ArrayList<>();
        boolean[][] visited = new boolean[n][m];
        dfs(list, visited, maze, 0, 0);

    }

    private static void dfs(ArrayList<int[]> list, boolean[][] visited, int[][] maze, int i, int j) {
        int n = maze.length;
        int m = maze[0].length;
        list.add(new int[]{i, j});
        if (i == n - 1 && j == m - 1) {
            for (int[] points : list) {
                System.out.println("(" + points[0] + "," + points[1] + ")");
            }
            return;
        }
        visited[i][j] = true;
        if (i - 1 >= 0 && !visited[i - 1][j] && maze[i - 1][j] == 0)
            dfs(list, visited, maze, i - 1, j);
        if (i + 1 < n && !visited[i + 1][j] && maze[i + 1][j] == 0)
            dfs(list, visited, maze, i + 1, j);
        if (j - 1 >= 0 && !visited[i][j - 1] && maze[i][j - 1] == 0)
            dfs(list, visited, maze, i, j - 1);
        if (j + 1 < m && !visited[i][j + 1] && maze[i][j + 1] == 0)
            dfs(list, visited, maze, i, j + 1);
        visited[i][j] = false;
        list.remove(list.size() - 1);
    }

}
